
layui.use(['jquery','layer','form','table','laydate','upload'],function(){
    var $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,upload = layui.upload;

    //普同检索 22/1/20 赵
    form.on('submit(sub)',function(data){
        $.ajax({
            url: '/advertisement/getRotationCharts'
            ,data: {
                'display': data.field.display
                ,'imgType': data.field.imgType
            }
            ,dataType: 'json'
            ,success:function(data){
                tableRender(data.data);
            }
        });
    });




//获取轮播图列表 22/1/20 赵
    getRotationCharts();
    function getRotationCharts(carouselId){
        $.ajax({
            url: '/advertisement/getRotationCharts'
            ,data: {'carouselId': carouselId}
            ,dataType: 'json'
            ,success:function(data){
                //渲染表格
                tableRender(data.data);
            }
        });
    }
//渲染表格 22/1/20 赵
    function tableRender(data){
        table.render({
            elem: '#layuiTbale'
            ,data: data
            ,toolbar: '#toolutil'
            ,page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局
                ,limits:[10,15,20]
                ,first: true
                ,last: true
            }
            ,limit: 10
            ,cols: [[
                {checkbox: true}
                ,{field: 'carouselId',title: '轮播提图编号',align: 'center'}
                ,{field: 'imgAddress',title: '图片地址',align: 'center',templet:function(data){
                    return '<img src="'+data.imgAddress+'"/>';
                    }}
                ,{field: 'createId',title: '创建人',align: 'center'}
                ,{field: 'imgTitle',title: '图片标题',align: 'center'}
                ,{field: 'imgType',title: '图片类型',align: 'center',templet:function(data){
                        if(data.imgType == '2'){
                            return '商品';
                        }else if(data.imgType == '3'){
                            return '视频';
                        }else{
                            return '数据错误';
                        }
                    }}
                ,{field: 'remarks',title: '备注',align: 'center'}
                ,{field: 'updateDate',title: '更新时间',align: 'center'}
                ,{title: '操作',align: 'center',templet:function(data){
                        return '<a onclick="edit('+data.carouselId+')" style="color: #009688;">编辑</a> ' +
                            '<a onclick="del(\''+data.carouselId+'\')" style="color: #009688;">删除</a>'
                    }}

            ]]
        });
    }
//编辑 22/1/20 赵
    edit = function edit(carouselId){
        $('#carouselId').val(carouselId);
        layer.open({
            type: 2
            ,title: '编辑用户'
            ,content: 'popup/rotationChart-list-edit.html'
            ,area: ['650px','550px']
        });
    }

//删除 22/1/20 赵
    del = function del(carouselId){
        layer.open({
            title: '删除轮播图'
            ,content: '您确定将此轮播图删除吗？'
            ,area: ['200px','200px']
            ,btn: ['确定','取消']
            ,yes:function(index){
                $.ajax({
                    url: '/advertisement/delRotationChart'
                    ,data: {'carouselId': carouselId}
                    ,dataType: 'json'
                    ,success:function(data){
                        layer.close(index);
                        getRotationCharts();
                        layer.msg('已删除');
                    }
                })
            }
            ,btn2:function(index){
                layer.close(index);
            }
        });
    }


//刷新 22/1/20 赵
    refresh = function refresh(){
        location.reload();

    }

//返回 22/1/20 赵



});
//返回首页
function backOff(){
    parent.jumpSystemHome();
}